﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Delegates
{
    class Program
    {
        delegate double OneDimFunction(double value);
        static void Main(string[] args)
        {
            OneDimFunction del1 = new OneDimFunction(f2);
            OneDimFunction del2 = f2;

            Console.WriteLine(f2(2));
            Console.WriteLine(del1(2));
            Console.WriteLine(del2(2));

            OneDimFunction fDel2 = f2;
            OneDimFunction fDel3 = f3;

            MyFunction(fDel2);
            MyFunction(fDel3);

            MyFunction(f2);
            MyFunction(f3);

            Plot(f2, 0, 5, 100);
            Plot(Math.Sin, 0, Math.PI / 2, 150);
        }

        static double f2(double x)
        {
            return x * x;
        }

        static double f3(double x)
        {
            return x * x * x;
        }

        static void MyFunction(OneDimFunction del)
        {
            Console.WriteLine(del(2));
        }

        static void Plot(OneDimFunction f, double a, double b, int points)
        {
            double dx = (b-a)/points;

            for (double x = a; x <= b; x += dx)
            {
                double y = f(x);
                // draw(x,y);
            }
        }
    }
}
